package com.example.act6.common.exception;

import java.util.Arrays;

/**
 * @ClassName: BusinessException
 * @Description: 业务逻辑异常
 * @Author: chenjiang
 * @Date: 2020-10-24 14:31
 * @Version: 1.0.0
 */
public class BusinessException extends RuntimeException{

    private Integer code;
    private String message;
    private String[] params;

    private BusinessException(){}

//    public BusinessException(Integer code) {
//        super(String.valueOf(code));
//        this.code = code;
//    }

    public BusinessException(String message) {
        super(message);
        this.message = message;
    }

    public BusinessException(Integer code,String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public BusinessException(Integer code,String message,String[] params) {
        super(message);
        this.code = code;
        this.message = message;
        this.params = params;
    }

    public BusinessException(Integer code,String message,Throwable cause) {
        super(message,cause);
        this.code = code;
        this.message = message;
    }

    public BusinessException(Integer code,String message,String[] params,Throwable cause) {
        super(message,cause);
        this.code = code;
        this.message = message;
        this.params = params;
    }

    public BusinessException(Integer code,String message,String params,Throwable cause) {
        super(message,cause);
        this.code = code;
        this.message = message;
        this.params = new String[]{params};
    }

    public Integer getCode() {
        return code;
    }

    @Override
    public String toString() {
        return "BusinessException{" +
                "code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", params=" + Arrays.toString(params) +
                '}';
    }
}
